package com.liuyjy.base.mybatisplus.handler;

import com.baomidou.mybatisplus.extension.plugins.handler.TableNameHandler;
import com.liuyjy.base.mybatisplus.cache.TableSuffixCache;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * 按天分表解析
 */
public class DaysTableNameParserEx implements TableNameHandler {


    @Override
    public String dynamicTableName(String sql, String tableName) {
        Object suffix = TableSuffixCache.getSuffix();
        if (suffix != null && !"".equals(suffix)) {
            return tableName + "_" + suffix;
        } else {
            String dateDay = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
            return tableName + "_" + dateDay;
        }
    }
}
